home *** CD-ROM | disk | FTP | other *** search
/ Champak 120 / Vol 120.iso / interfac / it.dig / scripts / __Packages / mx / controls / listclasses / SelectableRow.as < prev   
Text File  |  2010-11-09  |  11KB  |  358 lines

  1. class mx.controls.listclasses.SelectableRow extends mx.core.UIComponent
  2. {
  3.    static var LOWEST_DEPTH = -16384;
  4.    var state = "normal";
  5.    var disabledColor = 15263976;
  6.    var normalColor = 16777215;
  7.    function SelectableRow()
  8.    {
  9.       super();
  10.    }
  11.    function setValue(itmObj, state)
  12.    {
  13.       var _loc6_ = this.__height;
  14.       var _loc2_ = this.cell;
  15.       var _loc5_ = this.owner;
  16.       var _loc8_ = this.itemToString(itmObj);
  17.       if(_loc2_.getValue() != _loc8_)
  18.       {
  19.          _loc2_.setValue(_loc8_,itmObj,state);
  20.       }
  21.       var _loc4_ = _loc5_.getPropertiesAt(this.rowIndex + _loc5_.__vPosition).icon;
  22.       if(_loc4_ == undefined)
  23.       {
  24.          _loc4_ = _loc5_.__iconFunction(itmObj);
  25.          if(_loc4_ == undefined)
  26.          {
  27.             _loc4_ = itmObj[_loc5_.__iconField];
  28.             if(_loc4_ == undefined)
  29.             {
  30.                _loc4_ = _loc5_.getStyle("defaultIcon");
  31.             }
  32.          }
  33.       }
  34.       var _loc3_ = this.icon_mc;
  35.       if(_loc4_ != undefined && itmObj != undefined)
  36.       {
  37.          _loc3_ = this.createObject(_loc4_,"icon_mc",20);
  38.          _loc3_._x = 2;
  39.          _loc3_._y = (_loc6_ - _loc3_._height) / 2;
  40.          _loc2_._x = 4 + _loc3_._width;
  41.       }
  42.       else
  43.       {
  44.          _loc3_.removeMovieClip();
  45.          _loc2_._x = 2;
  46.       }
  47.       var _loc9_ = _loc3_ != undefined ? _loc3_._width : 0;
  48.       _loc2_.setSize(this.__width - _loc9_,Math.min(_loc6_,_loc2_.getPreferredHeight()));
  49.       _loc2_._y = (_loc6_ - _loc2_._height) / 2;
  50.    }
  51.    function size(Void)
  52.    {
  53.       var _loc3_ = this.backGround;
  54.       var _loc2_ = this.cell;
  55.       var _loc4_ = this.__height;
  56.       var _loc5_ = this.__width;
  57.       var _loc6_ = this.icon_mc != undefined ? this.icon_mc._width : 0;
  58.       _loc2_.setSize(_loc5_ - _loc6_,Math.min(_loc4_,_loc2_.getPreferredHeight()));
  59.       _loc2_._y = (_loc4_ - _loc2_._height) / 2;
  60.       this.icon_mc._y = (_loc4_ - this.icon_mc._height) / 2;
  61.       _loc3_._x = 0;
  62.       _loc3_._width = _loc5_;
  63.       _loc3_._height = _loc4_;
  64.       this.drawRowFill(_loc3_,this.normalColor);
  65.       this.drawRowFill(this.highlight,this.highlightColor);
  66.    }
  67.    function setCellRenderer(forceSizing)
  68.    {
  69.       var _loc3_ = this.owner.__cellRenderer;
  70.       var _loc4_ = undefined;
  71.       if(this.cell != undefined)
  72.       {
  73.          _loc4_ = this.cell._x;
  74.          this.cell.removeMovieClip();
  75.          this.cell.removeTextField();
  76.       }
  77.       var _loc2_ = undefined;
  78.       if(_loc3_ == undefined)
  79.       {
  80.          var _loc0_ = null;
  81.          _loc2_ = this.cell = this.createLabel("cll",0,{styleName:this});
  82.          _loc2_.styleName = this.owner;
  83.          _loc2_.selectable = false;
  84.          _loc2_.tabEnabled = false;
  85.          _loc2_.background = false;
  86.          _loc2_.border = false;
  87.       }
  88.       else if(typeof _loc3_ == "string")
  89.       {
  90.          var _loc0_ = null;
  91.          _loc2_ = this.cell = this.createObject(_loc3_,"cll",0,{styleName:this});
  92.       }
  93.       else
  94.       {
  95.          var _loc0_ = null;
  96.          _loc2_ = this.cell = this.createClassObject(_loc3_,"cll",0,{styleName:this});
  97.       }
  98.       _loc2_.owner = this;
  99.       _loc2_.listOwner = this.owner;
  100.       _loc2_.getCellIndex = this.getCellIndex;
  101.       _loc2_.getDataLabel = this.getDataLabel;
  102.       if(_loc4_ != undefined)
  103.       {
  104.          _loc2_._x = _loc4_;
  105.       }
  106.       if(forceSizing)
  107.       {
  108.          this.size();
  109.       }
  110.    }
  111.    function getCellIndex(Void)
  112.    {
  113.       return {columnIndex:0,itemIndex:this.owner.rowIndex + this.listOwner.__vPosition};
  114.    }
  115.    function getDataLabel()
  116.    {
  117.       return this.listOwner.labelField;
  118.    }
  119.    function init(Void)
  120.    {
  121.       super.init();
  122.       this.tabEnabled = false;
  123.    }
  124.    function createChildren(Void)
  125.    {
  126.       this.setCellRenderer(false);
  127.       this.setupBG();
  128.       this.setState(this.state,false);
  129.    }
  130.    function drawRow(itmObj, state, transition)
  131.    {
  132.       this.item = itmObj;
  133.       this.setState(state,transition);
  134.       this.setValue(itmObj,state,transition);
  135.    }
  136.    function itemToString(itmObj)
  137.    {
  138.       if(itmObj == undefined)
  139.       {
  140.          return " ";
  141.       }
  142.       var _loc2_ = this.owner.__labelFunction(itmObj);
  143.       if(_loc2_ == undefined)
  144.       {
  145.          _loc2_ = !(itmObj instanceof XMLNode) ? itmObj[this.owner.__labelField] : itmObj.attributes[this.owner.__labelField];
  146.          if(_loc2_ == undefined)
  147.          {
  148.             _loc2_ = " ";
  149.             if(typeof itmObj == "object")
  150.             {
  151.                for(var _loc4_ in itmObj)
  152.                {
  153.                   if(_loc4_ != "__ID__")
  154.                   {
  155.                      _loc2_ = itmObj[_loc4_] + ", " + _loc2_;
  156.                   }
  157.                }
  158.                _loc2_ = _loc2_.substring(0,_loc2_.length - 2);
  159.             }
  160.             else
  161.             {
  162.                _loc2_ = itmObj;
  163.             }
  164.          }
  165.       }
  166.       return _loc2_;
  167.    }
  168.    function setupBG(Void)
  169.    {
  170.       var _loc0_ = null;
  171.       var _loc2_ = this.backGround = this.createEmptyMovieClip("bG_mc",mx.controls.listclasses.SelectableRow.LOWEST_DEPTH);
  172.       this.drawRowFill(_loc2_,this.normalColor);
  173.       this.highlight = this.createEmptyMovieClip("tran_mc",mx.controls.listclasses.SelectableRow.LOWEST_DEPTH + 10);
  174.       _loc2_.owner = this;
  175.       _loc2_.grandOwner = this.owner;
  176.       _loc2_.onPress = this.bGOnPress;
  177.       _loc2_.onRelease = this.bGOnRelease;
  178.       _loc2_.onRollOver = this.bGOnRollOver;
  179.       _loc2_.onRollOut = this.bGOnRollOut;
  180.       _loc2_.onDragOver = this.bGOnDragOver;
  181.       _loc2_.onDragOut = this.bGOnDragOut;
  182.       _loc2_.useHandCursor = false;
  183.       _loc2_.trackAsMenu = true;
  184.       _loc2_.drawRect = this.drawRect;
  185.       this.highlight.drawRect = this.drawRect;
  186.    }
  187.    function drawRowFill(mc, newClr)
  188.    {
  189.       mc.clear();
  190.       mc.beginFill(newClr);
  191.       mc.drawRect(1,0,this.__width,this.__height);
  192.       mc.endFill();
  193.       mc._width = this.__width;
  194.       mc._height = this.__height;
  195.    }
  196.    function setState(newState, transition)
  197.    {
  198.       var _loc2_ = this.highlight;
  199.       var _loc9_ = this.backGround;
  200.       var _loc4_ = this.__height;
  201.       var _loc3_ = this.owner;
  202.       if(!_loc3_.enabled)
  203.       {
  204.          if(newState == "selected" || this.state == "selected")
  205.          {
  206.             this.highlightColor = _loc3_.getStyle("selectionDisabledColor");
  207.             this.drawRowFill(_loc2_,this.highlightColor);
  208.             _loc2_._visible = true;
  209.             _loc2_._y = 0;
  210.             _loc2_._height = _loc4_;
  211.          }
  212.          else
  213.          {
  214.             _loc2_._visible = false;
  215.             this.normalColor = _loc3_.getStyle("backgroundDisabledColor");
  216.             this.drawRowFill(_loc9_,this.normalColor);
  217.          }
  218.          this.cell.__enabled = false;
  219.          this.cell.setColor(_loc3_.getStyle("disabledColor"));
  220.       }
  221.       else
  222.       {
  223.          this.cell.__enabled = true;
  224.          if(transition && (newState == this.state || newState == "highlighted" && this.state == "selected"))
  225.          {
  226.             this.isChangedToSelected = true;
  227.             return undefined;
  228.          }
  229.          var _loc6_ = _loc3_.getStyle("selectionDuration");
  230.          var _loc7_ = 0;
  231.          if(this.isChangedToSelected && newState == "selected")
  232.          {
  233.             transition = false;
  234.          }
  235.          var _loc8_ = transition && _loc6_ != 0;
  236.          if(newState == "normal")
  237.          {
  238.             _loc7_ = _loc3_.getStyle("color");
  239.             this.normalColor = this.getNormalColor();
  240.             this.drawRowFill(_loc9_,this.normalColor);
  241.             if(_loc8_)
  242.             {
  243.                _loc6_ /= 2;
  244.                _loc2_._height = _loc4_;
  245.                _loc2_._width = this.__width;
  246.                _loc2_._y = 0;
  247.                this.bGTween = new mx.effects.Tween(this,_loc4_ + 2,_loc4_ * 0.2,_loc6_,5);
  248.             }
  249.             else
  250.             {
  251.                _loc2_._visible = false;
  252.             }
  253.             delete this.isChangedToSelected;
  254.          }
  255.          else
  256.          {
  257.             this.highlightColor = _loc3_.getStyle(newState != "highlighted" ? "selectionColor" : "rollOverColor");
  258.             this.drawRowFill(_loc2_,this.highlightColor);
  259.             _loc2_._visible = true;
  260.             _loc7_ = _loc3_.getStyle(newState != "highlighted" ? "textSelectedColor" : "textRollOverColor");
  261.             if(_loc8_)
  262.             {
  263.                _loc2_._height = _loc4_ * 0.5;
  264.                _loc2_._y = (_loc4_ - _loc2_._height) / 2;
  265.                this.bGTween = new mx.effects.Tween(this,_loc2_._height,_loc4_ + 2,_loc6_,5);
  266.                var _loc10_ = _loc3_.getStyle("selectionEasing");
  267.                if(_loc10_ != undefined)
  268.                {
  269.                   this.bGTween.easingEquation = _loc10_;
  270.                }
  271.             }
  272.             else
  273.             {
  274.                _loc2_._y = 0;
  275.                _loc2_._height = _loc4_;
  276.             }
  277.          }
  278.          this.cell.setColor(_loc7_);
  279.       }
  280.       this.state = newState;
  281.    }
  282.    function onTweenUpdate(val)
  283.    {
  284.       this.highlight._height = val;
  285.       this.highlight._y = (this.__height - val) / 2;
  286.    }
  287.    function onTweenEnd(val)
  288.    {
  289.       this.onTweenUpdate(val);
  290.       this.highlight._visible = this.state != "normal";
  291.    }
  292.    function getNormalColor(Void)
  293.    {
  294.       var _loc3_ = undefined;
  295.       var _loc2_ = this.owner;
  296.       if(!this.owner.enabled)
  297.       {
  298.          _loc3_ = _loc2_.getStyle("backgroundDisabledColor");
  299.       }
  300.       else
  301.       {
  302.          var _loc5_ = this.rowIndex + _loc2_.__vPosition;
  303.          if(this.rowIndex == undefined)
  304.          {
  305.             _loc3_ = _loc2_.getPropertiesOf(this.item).backgroundColor;
  306.          }
  307.          else
  308.          {
  309.             _loc3_ = _loc2_.getPropertiesAt(_loc5_).backgroundColor;
  310.          }
  311.          if(_loc3_ == undefined)
  312.          {
  313.             var _loc4_ = _loc2_.getStyle("alternatingRowColors");
  314.             if(_loc4_ == undefined)
  315.             {
  316.                _loc3_ = _loc2_.getStyle("backgroundColor");
  317.             }
  318.             else
  319.             {
  320.                _loc3_ = _loc4_[_loc5_ % _loc4_.length];
  321.             }
  322.          }
  323.       }
  324.       return _loc3_;
  325.    }
  326.    function invalidateStyle(propName)
  327.    {
  328.       this.cell.invalidateStyle(propName);
  329.       super.invalidateStyle(propName);
  330.    }
  331.    function bGOnPress(Void)
  332.    {
  333.       this.grandOwner.pressFocus();
  334.       this.grandOwner.onRowPress(this.owner.rowIndex);
  335.    }
  336.    function bGOnRelease(Void)
  337.    {
  338.       this.grandOwner.releaseFocus();
  339.       this.grandOwner.onRowRelease(this.owner.rowIndex);
  340.    }
  341.    function bGOnRollOver(Void)
  342.    {
  343.       this.grandOwner.onRowRollOver(this.owner.rowIndex);
  344.    }
  345.    function bGOnRollOut(Void)
  346.    {
  347.       this.grandOwner.onRowRollOut(this.owner.rowIndex);
  348.    }
  349.    function bGOnDragOver(Void)
  350.    {
  351.       this.grandOwner.onRowDragOver(this.owner.rowIndex);
  352.    }
  353.    function bGOnDragOut(Void)
  354.    {
  355.       this.grandOwner.onRowDragOut(this.owner.rowIndex);
  356.    }
  357. }
  358.